/*************************************************
*      Filename: main_without_show.cu
*        Coding: utf-8
*        Author: Futuan Li
*         Email: lifutuan@galasports.net
*      HomePage: http://www.galasports.net
*  Copyright(C): InnoReal Technology Co.,Ltd.
*       Version: 0.0.1
*    CreateDate: 2018-04-24 15:50:58
*    LastChange: 2018-07-06 21:18:37
*          Desc: 
*       History: 
*************************************************/


#include <innoreal/utils/innoreal_helper.hpp>
#include <innoreal/utils/innoreal_timer.hpp>
#include "input_data.h"
#include "constant.h"
#include "gn_solver.h"
#include "distance_twomesh.h"
//#include "keyframe_find.h"
#include "keyframe_movingpoint.h"
#include <vector>
//#include "output_vector1d2d.h"
//#include "output_vec1d2d_typename.h"


int main(int argc, char **argv) {

/*
    //one step for test
  int source_id = atoi(argv[1]), target_id = atoi(argv[2]);
  InputData *input_data = new InputData;
  char file_src[100], file_tar[100];
  sprintf(file_src, "/data/workspace/Offline4D/data/168/mesh/mesh%d.obj", source_id);
  sprintf(file_tar, "/data/workspace/Offline4D/data/168/mesh/mesh%d.obj", target_id);
  input_data->Init(file_src, file_tar);

  for (int iter = 0; iter < 1; ++iter) {
    input_data->GetIijSet();
  }

  SolverPara gnsolver_param(true, 10.0f, false, 3.0f, true, 3.0f, 1, 1000.0f);

  GNSolver *gn_solver = new GNSolver;
  gn_solver->InitSovler(input_data, gnsolver_param);
  innoreal::InnoRealTimer timer;
  for (int iter = 0; iter < 10; ++iter) {
    timer.TimeStart();
    gn_solver->Run(1);
    timer.TimeEnd();
    printf("time of %d iters: %f ms\n", iter + 1, timer.TimeGap_in_ms());
  }
	
  DisTwoMesh distmesh;
  timer.TimeStart();
  //double Dis = distmesh.Hausdorff_Simple(input_data);
  double Dis = distmesh.Hausdorff_Average(input_data);
  //double Dis = distmesh.Hausdorff_igl(input_data);
  timer.TimeEnd();
  INNOREALI("The time of Hausdorff distance : %f ms \n", timer.TimeGap_in_ms());
  INNOREALI("The Hausdorff Distance is : %f \n", Dis);


  delete gn_solver;
  delete input_data;
*/



/*
 //muilti-step pragram for test!
  std::vector<int> keyframe;
  std::vector<double> hausdorff_dis;
  int sourceframe_Num = atoi(argv[1]);
    InputData *input_data;
    GNSolver *gn_solver;
    DisTwoMesh *distmesh;
  for(int iter_out = 0; iter_out < sourceframe_Num-1; iter_out++) {
       input_data = new InputData;
      char file_src[100],file_tar[100];
      sprintf(file_src, "/data/workspace/Offline4D/data/168/mesh/mesh%d.obj", iter_out);
      sprintf(file_tar, "/data/workspace/Offline4D/data/168/mesh/mesh%d.obj", iter_out+1);

    input_data->Init(file_src,file_tar);

    for (int iter = 0; iter < 1; ++iter) {
      input_data->GetIijSet();
    }

    SolverPara gnsolver_param(true, 10.0f, false, 3.0f, true, 3.0f, 1, 1000.0f);

     gn_solver = new GNSolver;
    gn_solver->InitSovler(input_data, gnsolver_param); //error: InitSovler? -->InitSolver
    innoreal::InnoRealTimer timer;
    for (int iter =0; iter < 10; ++iter) {
      timer.TimeStart();
      gn_solver->Run(1);
      timer.TimeEnd();
      printf("time of %d iters: %f ms \n", iter + 1, timer.TimeGap_in_ms());
    }

     distmesh = new DisTwoMesh;
    timer.TimeStart();
      //double Dis = distmesh.Hausdorff_Simple(input_data);
      double Dis = distmesh->Hausdorff_Average(input_data);
    //double Dis = distmesh->Hausdorff_igl(input_data);
    timer.TimeEnd();
    INNOREALI("The time of Hausdorff distance : %f ms\n", timer.TimeGap_in_ms());
    hausdorff_dis.push_back(Dis);
    INNOREALI("The %dth iteration and the hausdorff diftance is:%f\n", iter_out+1, Dis);
 
  }
  delete distmesh;
  delete gn_solver;
  delete input_data;
*/

  //声明指针或对象
//	KeyFrameFind *keyframe_find = new KeyFrameFind;
	KeyFrameMovingPoint * keyframe_movingpoint = new KeyFrameMovingPoint;

  //初始化数据
	int Frame_sum = atoi(argv[1]);  // our data is asked as the behavier /data/workspace/Offline4D/data/168/mesh such as mesh0.obj mesh1.obj ......
  	int Frame_given = atoi(argv[2]); // 这里的Frame_sum特指所有的帧的数据而且是从0开始到第Frame_sum帧;但是Frame_given是特指一贡选取了Frame_given帧.
	INNOREALI("Frame_sum: %d    Frame_given: %d \n", Frame_sum, Frame_given);

  //算法实现
  //case 1(暴力直接选取法): 获得关键帧编号和对应的Hausdorff距离,关键的文件 keyframe_find.cu keyframe_find.h distance_twomesh.cu distance_twomesh.h
	/*
	std::vector<std::vector<double> > distance_eva;
	if(Frame_given >= Frame_sum)
		INNOREALI("please input the parameters again: Para_1 > Para_2 is required.");
	else {
		keyframe_find->KFrame_F(Frame_sum,Frame_given); // the first way-----on way
	}
	for(int i = 0; i < Frame_given; i++){
		INNOREALI("%d \n", keyframe_find->keyframe[i]);
	}
  */

  //case 2(移动节点方法): 获得关键帧编号,关键的文件 keyframe_movingpoint.cu keyframe_movingpoint.h  calculate_total_evalation.cu calculate_total_evalation.h moving_point.cu moving_point.h distance_twomesh.cu distance_twomesh.h
  keyframe_movingpoint->KFrame_KNN_Standard(Frame_sum, Frame_given);


	// output data as you want
	////Output_Vector_Typename<int> output_vector_typename;
  ////output_vector_typename.Vec1dint_Output(keyframe_movingpoint->keyframe);
	
	//Output_Vector output_vector;
	//output_vector.Vec1dint_Output(keyframe_movingpoint->keyframe);
	//output_vector.Vec2ddouble_Output(keyframe_movingpoint->diseva);
  //output_vector.Keyframe_Output_File(keyframe_find->keyframe, Frame_sum, "test_keyframe.csv");
	

	delete keyframe_movingpoint;
//	delete keyframe_find;
  return 0;
}
